<template>
    <div class="CustomerRemarkeItem">
        <!--  -->
        <el-dialog
            v-drag
            :title="isTitleValue"
            :visible.sync="showDialogFroms"
            width="900px"
            max-width="900px"
            :append-to-body="true"
            top="8vh"
            class="CustomerRemarkeItem"
            :close-on-click-modal="false"
            center
        >
            <el-form :model="formData" :rules="rules" ref="ruleForm" label-width="130px">
                <el-row>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="姓名:" class="text_fl" prop="custName">
                                <el-input v-model.trim="formData.custName"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="性别:" class="text_fl">
                                <el-select v-model="formData.sex" placeholder="请选择性别">
                                    <el-option label="男" value="男" key="男"></el-option>
                                    <el-option label="女" value="女" key="女"></el-option>
                                </el-select>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="联系方式1:" class="text_fl" prop="phoneNumberOne">
                                <el-input v-model.trim="formData.phoneNumberOne"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="联系方式2:" class="text_fl">
                                <el-input v-model.trim="formData.phoneNumberTwo"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="证件号:" class="text_fl" prop="idNo">
                                <el-input
                                    v-model.trim="formData.idNo"
                                ></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="客户类型:" class="text_fl">
                                <el-select v-model="formData.custType" placeholder="请选择客户类型">
                                    <el-option
                                        v-for="item in CUSTTYPE_option"
                                        :label="item.label"
                                        :value="item.code"
                                        :key="item.code"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="是否优先排队:" class="text_fl">
                                <el-radio label="1" v-model="formData.isPriorityQueue" border>是</el-radio>
                                <el-radio label="0" v-model="formData.isPriorityQueue" border>否</el-radio>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="优先级别:" class="text_fl">
                                <el-select v-model="formData.priorityLevel" placeholder="请选择优先级别">
                                    <el-option
                                            v-for="item in priorityLevelOption"
                                            :label="item.label"
                                            :value="item.code"
                                            :key="item.code"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="部门:" class="text_fl">
                                <el-input v-model.trim="formData.dept" class="dagWidth"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="职位:" class="text_fl">
                                <el-input v-model.trim="formData.position" class="dagWidth"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="卡号1:" class="text_fl" prop="idNo">
                                <el-input
                                        v-model.trim="formData.cardNumberOne"
                                ></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="卡号2:" class="text_fl" prop="idNo">
                                <el-input
                                        v-model.trim="formData.cardNumberTwo"
                                ></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="描述1:" class="text_fl">
                                <el-input
                                    type="textarea"
                                    :autosize="{minRows:3,maxRows:4}"
                                    v-model.trim="formData.remark"
                                ></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="12">
                        <div class="text_center width30">
                            <el-form-item label="描述2:" class="text_fl">
                                <el-input
                                    type="textarea"
                                    :autosize="{minRows:3,maxRows:4}"
                                    v-model.trim="formData.remarkTwo"
                                ></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button
                    type="primary"
                    size="small"
                    icon="el-icon-circle-close"
                    @click="formClose"
                >取 消</el-button>
                <el-button
                    type="primary"
                    v-if="(isTitleValue == '修改客户标签')"
                    size="small"
                    @click="updataInfo"
                >修 改</el-button>
                <el-button
                    type="primary"
                    v-else
                    size="small"
                    @click="addInfo"
                    icon="el-icon-circle-check"
                >确定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { closePage, } from '@/utils/Common';
import { isEmptyObject } from '@/utils/Object';
import { getToken } from '@/utils/auth'

export default {
    name: 'CustomerRemarkeItem',
    props: {
        updataInfocurres: {
            type: Object,
            default: {},
        },
        isTitleValue: {
            type: String,
            default: '新增',
        },
        CUSTTYPE_option: {
            type: Array,
            default: [],
        },
        priorityLevelOption: {
            type: Array,
            default: [],
        },


    },
    data() {
        return {
            formData: {
                id: '',
                custName: '',//姓名
                sex: '',//性别
                phoneNumberOne: '',//手机号
                phoneNumberTwo: '',//固话
                cardNumberOne: '',//卡号1
                cardNumberTwo: '',//卡号2
                // nbrMths: '',
                idNo: '',//证件号
                remark: '',//描述1
                updateUser: '',//操作员
                custType: '',//客户类型
                position: '',//职位
                dept: '',//部门
                remarkTwo: '',//描述2
                isPriorityQueue: '',//是否优先排队
                priorityLevel: '',//优先级别

            },

            showDialogFroms: true,
            hsbankCookies: '',
            rules: {
                custName: [{ required: true, message: '客户名称不能为空', trigger: 'blur' },],
                idNo: [{ required: true, message: '证件号码不能为空', trigger: 'blur' },],
                phoneNumberOne: [{ required: true, message: '联系方式1不能为空', trigger: 'blur' },],
                cardNumberOne: [{ required: true, message: '卡号1不能为空', trigger: 'blur' },],
            }
        }
    },
    mounted() {
        this.getViewInfo();
        this.getUpdataInfoCur();
    },
    methods: {
        // 查字典 赋值
        async getViewInfo() {
            this.hsbankCookies = JSON.parse(await getToken());
            console.log('this.hsbankCookies', this.hsbankCookies);
            this.formData.updateUser = this.hsbankCookies.userName;

            console.log('this.CUSTTYPE_option', this.CUSTTYPE_option);
            console.log('this.formData.custType', this.formData.custType);
            console.log('this.priorityLevelOption', this.priorityLevelOption);
        },
        // 父页面传值过来
        getUpdataInfoCur() {
            console.log('this.updataInfocurres', this.updataInfocurres);
            if (this.isTitleValue == '修改客户标签') {
                if (!isEmptyObject(this.updataInfocurres)) {
                    this.formData = Object.assign({}, this.updataInfocurres);
                }
            }
        },
        // 修改数据
        updataInfo() {
            this.$refs.ruleForm.validate((valid) => {
                if (valid) {
                    let params = {
                        id: this.formData.id,
                        custName: this.formData.custName,//姓名
                        sex: this.formData.sex,//性别
                        phoneNumberOne: this.formData.phoneNumberOne,//手机号1
                        phoneNumberTwo: this.formData.phoneNumberTwo,//手机号2
                        cardNumberOne: this.formData.cardNumberOne,//手机号1
                        cardNumberTwo: this.formData.cardNumberTwo,//手机号2
                        idNo: this.formData.idNo,//证件号
                        custType: this.formData.custType,
                        remark: this.formData.remark,//描述1
                        updateUser: this.formData.updateUser,//操作员
                        position: this.formData.position, //职位
                        dept: this.formData.dept,//部门
                        remarkTwo: this.formData.remarkTwo,//描述2s
                        isPriorityQueue: this.formData.isPriorityQueue,//是否优先排队
                        priorityLevel: this.formData.priorityLevel,//优先级别

                    };
                    console.log('params', params);
                    // params = Object.assign({}, params, this.formData);
                    this.$post.customerRemarke.updateRemarke(params).then((res) => {
                        if (res.data.success) {
                            this.$message.success('修改成功！');
                            this.formClose();
                        } else {
                            if (res.data.msg == '数据已存在') {
                                this.$message.error('手机号重复,数据添加失败！')
                            } else {
                                this.$message.error(res.data.msg + '!');
                            }

                        }
                    });
                }
            });
        },
        // 添加新的数据
        addInfo() {
            this.$refs.ruleForm.validate((valid) => {
                if (valid) {
                    let params = {
                        custName: this.formData.custName,//姓名
                        sex: this.formData.sex,//性别
                        phoneNumberOne: this.formData.phoneNumberOne,//手机号1
                        phoneNumberTwo: this.formData.phoneNumberTwo,//手机号1
                        cardNumberOne: this.formData.cardNumberOne,//卡号1
                        cardNumberTwo: this.formData.cardNumberTwo,//卡号2
                        remarkTwo: this.formData.remarkTwo,//描述1
                        idNo: this.formData.idNo,//证件号
                        custType: this.formData.custType,
                        remark: this.formData.remark,//描述1
                        updateUser: this.formData.updateUser,//操作员
                        position: this.formData.position, //职位
                        dept: this.formData.dept,//部门
                        isPriorityQueue: this.formData.isPriorityQueue,//是否优先排队
                        priorityLevel: this.formData.priorityLevel,//优先级别

                    };

                    // params = Object.assign({}, params, this.formData);
                    console.log('params::::', params);
                    this.$post.customerRemarke.addRemarke(params).then((res) => {
                        if (res.data.success) {
                            this.$message.success('添加成功！');
                            this.formClose();
                        } else {
                            if (res.data.msg == '数据已存在') {
                                this.$message.error('手机号重复,数据添加失败！')
                            } else {
                                this.$message.error(res.data.msg + '!');
                            }

                        }
                    });
                }
            });

        },
        // 取消
        formClose() {
            this.showDialogFroms = false;
            this.$emit('parnetFun');
        }
    },
}
</script>
<style  lang='scss'>
.CustomerRemarkeItem {
    .el-form-item__content {
        text-align: left;
    }

    .dagWidth .el-input__inner {
        width: 100%;
    }
}
</style>